#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.10.0
 Author:         www.xzaz.nl

 Script Function:
    Color picker / chooser and copy to clipboard

#ce ----------------------------------------------------------------------------
#NoTrayIcon
#Include <Misc.au3>
#include <GUIConstants.au3>
#include <Color.au3>
$dll = DllOpen("user32.dll")
Global $return = 0                                                                      ; 0 is aan 1 is uit
Global $copy = 0                                                                        ; 0 is niks, 1 is RGB, 2 is HEX
Global $titel = "colorcopy"
Global $pixmouseget,$color,$colorpick,$colortxt,$RGB_check,$HEX_check,$movelabel,$hexcolor  ;Globals voor functies

;==> Begin GUI
$gui = GUICreate($titel,100,100,(@DesktopWidth - 100)/2,(@DesktopHeight - 100) /2,BitOR($WS_POPUP,$WS_BORDER),$WS_EX_TOPMOST) 
$movelabel = GuiCtrlCreateLabel("",0,0,100,15)
;GUICtrlCreateLabel ( "text", left, top [, width [, height [, style [, exStyle]]]] )
$colortxt = GuiCtrlCreateLabel("hex color",0,40,99,30,$SS_CENTER)
GuiCtrlSetState(-1,$GUI_HIDE) 
$colorrgbtxt = GuiCtrlCreateLabel("rgb color",0,40,99,30,$SS_CENTER)
GuiCtrlSetState(-1,$GUI_HIDE)
$RGB_check = GUICtrlCreateRadio ("RGB", 5, 10,70)
$HEX_check = GUICtrlCreateRadio ("HEX", 5, 30,70)
$colorpick = GuiCtrlCreateButton("color-pick",10,60,80)
GUICtrlSetState ($RGB_check, $GUI_CHECKED)
GUISetState (@SW_SHOW)    
;== Einde GUI 

;==> Begin While
While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
        DllClose($dll)
        ExitLoop
    Case $colorpick
        ; zet GUI uit
        GUICtrlSetState($colorpick,$GUI_HIDE)
        GuiCtrlSetState($RGB_check,$GUI_HIDE)
        GuiCtrlSetState($HEX_check,$GUI_HIDE)
         
    if BitAND(GUICtrlRead($RGB_check), $GUI_CHECKED) = $GUI_CHECKED Then
        $copy = 1
        GuiCtrlSetState($colorrgbtxt,$GUI_SHOW)
    Elseif BitAnd(GUiCtrlRead($HEX_check), $GUI_CHECKED) = $GUI_CHECKED Then
        $copy = 2
        GuiCtrlSetState($colortxt,$GUI_SHOW)
    Else
        MsgBox(16,"Error!","Foutje: 1")
        Exit 0
    Endif
    $currentpos = WinGetPos($titel) 
    WinMove($Titel,"",$currentpos[0],$currentpos[1],100,60)
    
    Do
        Sleep(50)
        _Colorpickfun()
    Until $return = 1
    GUICtrlSetState($colorpick,$GUI_SHOW)
    GuiCtrlSetState($RGB_check,$GUI_SHOW)
    GuiCtrlSetState($HEX_check,$GUI_SHOW)
    
    GuiCtrlSetState($colortxt,$GUI_HIDE)
    GuiCtrlSetState($colorrgbtxt,$GUI_HIDE)
    

    
        if Stringleft($hexcolor,1) = 0 OR Stringleft($hexcolor,1) = 1 OR Stringleft($hexcolor,1) = 2 OR Stringleft($hexcolor,1) = 3 OR Stringleft($hexcolor,1) = 4 OR Stringleft($hexcolor,1) = 5 OR Stringleft($hexcolor,1) = 6 OR Stringleft($hexcolor,1) = 7 OR Stringleft($hexcolor,1) = 8 OR Stringleft($hexcolor,1) = 9 OR Stringleft($hexcolor,1) = 0  Then
    GUICtrlSetColor($RGB_check,0xFFFFFF)
    GUICtrlSetColor($HEX_check,0xFFFFFF)
    
    Endif
    
    if StringLeft($hexcolor,1) = "A" OR Stringleft($hexcolor,1) = "B" OR Stringleft($hexcolor,1) = "C" OR Stringleft($hexcolor,1) = "D" OR Stringleft($hexcolor,1) = "E" OR Stringleft($hexcolor,1) = "F" Then
    GUICtrlSetColor($RGB_check,0x000000)
    GUICtrlSetColor($HEX_check,0x000000)
    Endif
    
    $currentpos = WinGetPos($titel) 
    WinMove($Titel,"",$currentpos[0],$currentpos[1],100,100)
    $return = 0
    if $copy = 1 Then ; RGB copy
        ClipPut(GuiCtrlRead($colorrgbtxt))
    Elseif $copy = 2 Then ;HEX copy
    ClipPut(hex($pixmouseget,6))
    Else
    msgBox(16,"Error!","Foutje: 2")
    Endif 

    Case $movelabel
        _Drag()
    EndSwitch
Wend
;==> End While

;==>Voor het kiezen van een kleur buiten het programma om, END om het programma te stoppen
func _Colorpickfun()
        $mousepos = MouseGetPos()
        $pixmouseget = PixelGetColor($mousepos[0],$mousepos[1])
        $hexcolor = hex($pixmouseget,6)
        ;MsgBox(0,"",Stringleft($hexcolor,1))
        ;a b c d e f
    
    if Stringleft($hexcolor,1) = 0 OR Stringleft($hexcolor,1) = 1 OR Stringleft($hexcolor,1) = 2 OR Stringleft($hexcolor,1) = 3 OR Stringleft($hexcolor,1) = 4 OR Stringleft($hexcolor,1) = 5 OR Stringleft($hexcolor,1) = 6 OR Stringleft($hexcolor,1) = 7 OR Stringleft($hexcolor,1) = 8 OR Stringleft($hexcolor,1) = 9 OR Stringleft($hexcolor,1) = 0  Then
    _number(0xFFFFFF)
    Endif
    
    if StringLeft($hexcolor,1) = "A" OR Stringleft($hexcolor,1) = "B" OR Stringleft($hexcolor,1) = "C" OR Stringleft($hexcolor,1) = "D" OR Stringleft($hexcolor,1) = "E" OR Stringleft($hexcolor,1) = "F" Then
    _number(0x000000)
    Endif
            If _IsPressed("23", $dll) Then
                $return = 1
            EndIf
EndFunc
;==> Einde

Func _number($colorchance)
        if $copy = 1 Then ;RGB
        GUICtrlSetColor($colorrgbtxt,$colorchance)
        GuiSetBKColor($pixmouseget)
        $iRedColor = _ColorGetRed( $pixmouseget ) ;Red
        $iGreenColor = _ColorGetGreen ( $pixmouseget ) ;Green
        $iBlueColor = _ColorGetBlue ( $pixmouseget ) ;$Blue
        GuictrlSetData($colorrgbtxt,$iRedColor & "," & $iGreenColor & "," & $iBlueColor)
        Elseif $copy = 2 Then ;Hex
        GUICtrlSetColor($colortxt,$colorchance)
        GuiSetBKColor($pixmouseget)
        GuictrlSetData($colortxt,hex($pixmouseget,6))
        Endif
EndFunc

Func _Drag()
    dllcall("user32.dll","int","ReleaseCapture")
    dllcall("user32.dll","int","SendMessage","hWnd", $gui,"int",$WM_NCLBUTTONDOWN,"int", $HTCAPTION,"int", 0)
EndFunc